﻿// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Plugin.FileExplorer
{
    using System;
    using System.Drawing;
    using System.Resources;
    using System.Windows.Forms;

    using CE.API;

    using WeifenLuo.WinFormsUI.Docking;

    [CEPlugin(CEPluginWindowType.DockWindow)]
    public class FileExplorer : ICEPlugin
    {
        #region Fields

        private IDockContent activeTab;
        private ICEPluginHost host;

        #endregion Fields

        #region Constructors

        public FileExplorer()
        {
            activeTab = null;
        }

        #endregion Constructors

        #region Properties

        public bool AbleToLoadFiles
        {
            get { return false; }
        }

        public string Author
        {
            get { return "Jithu Jose"; }
        }

        public bool HasContextMenu
        {
            get { return false; }
        }

        public bool HasMenu
        {
            get { return true; }
        }

        public bool HasTabMenu
        {
            get { return false; }
        }

        public ICEPluginHost Host
        {
            get { return host; }

            set { host = value; }
        }

        public string Name
        {
            get { return "File Explorer"; }
        }

        public Control OptionPanel
        {
            get { return null; }
        }

        public Image PluginImage
        {
            get
            {
                var mngr =
					new ResourceManager("CE.Plugin.FileExplorer.Properties.Resources", GetType().Assembly);
                return (Image) mngr.GetObject("Icon");
            }
        }

        public CEPluginWindowType Type
        {
            get { return CEPluginWindowType.DockWindow; }
        }

        public string Version
        {
            get { return "1.0.0.0"; }
        }

        public bool IsCompatible
        {
            get {
                return Environment.OSVersion.Version.Major == 6;
            }
        }

        #endregion Properties

        #region Methods

        public void ActiveContentChanged(IDockContent tab)
        {
            if (tab != null)
            {
                Type[] types = tab.GetType().GetInterfaces();
                foreach (Type t in types)
                {
                    if (t == typeof (ICEPluginTab))
                    {
                        activeTab = tab;
                        return;
                    }
                }
                activeTab = null;
            }
        }

        public void ApplyOptions()
        {
            throw new NotImplementedException();
        }

        public bool CheckContentString( string contentString)
        {
            if (contentString.Contains("|"))
            {
                string[] splt = contentString.Split('|');
                if (splt[0] == typeof (FrmFileExplorer).ToString())
                {
                    return true;
                }
            }
            return false;
        }

        public void Close()
        {
            //throw new NotImplementedException();
			
        }

        public IDockContent GetContent(string contentString)
        {
            FrmFileExplorer explorer = new FrmFileExplorer();
            explorer.Icon = Icon.FromHandle(((Bitmap) PluginImage).GetHicon());
            string[] splt = contentString.Split('|');
            //browser.Navigate(splt[1]);
            explorer.Host = host;
            return explorer;
        }

        public ToolStripMenuItem[] GetContextMenu()
        {
            return null;
        }

        public ToolStripMenuItem GetMenu()
        {
            ToolStripMenuItem tsmi = new ToolStripMenuItem("File Explorer");
            tsmi.Image = PluginImage;
			tsmi.Click += new EventHandler(CreateExplorer);
            return tsmi;
        }

		private void CreateExplorer(object sender, EventArgs e)
		{
            FrmFileExplorer explorer = new FrmFileExplorer();
			//explorer.Icon = Icon.FromHandle(((Bitmap)PluginImage).GetHicon());
			explorer.Host = host;
            host.AddDockContent(explorer, DockState.Document);
		}

        public ToolStripMenuItem[] GetTabMenu()
        {
            return null;
        }

        public bool LoadFile( string filePath)
        {
            return false;
        }

        public void Start()
        {
            
        }

        #endregion Methods
    }
}